home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
retain20.zip
/
RETAIN.BAT
< prev
next >
Wrap
DOS Batch File
|
1992-12-11
|
15KB
|
346 lines
echo off
rem ===RETAIN.BAT, vs. 2.0, 11/12-92===
if "%1"=="" echo --- RETAIN 2.0 (c) 1992, Jim Groeneveld; retains current path up to 7 levels.
rem if no argument at all make first one dummy + to auto-set second one later:
if "%1"=="" %0 +
if "%1"=="?" goto Help
if "%1"=="/?" goto Help
if "%1"=="-?" goto Help
if "%1"==".path" goto Path
rem if second argument (return-file specification) not given determine it:
rem (no check on erroneous presence of .BAT extension possible)
if "%2"=="" goto AltRtn
if "%1"==".notfound" goto NoPath
if "%1"=="*" if exist %2.BAT %2 *
if "%1"=="*" if not exist %2.BAT goto NoList
if "%1"==".list" goto List
if "%1"==".recreate" goto Create
if "%1"==".return" goto RETURN
if "%1"==".reversed" goto RETURN
if not "%1"=="+" goto RETAIN
rem %1 is the location or specification of the auxiliary file $RETURN$.AUX
:Determine
rem Determination of location (and name) of auxiliary file $RETURN$.AUX in/as:
rem a. the first and only parameter when calling RETAIN (not checked here)
rem 1. the full _path_ only, incl. trailing '\' (e.g. 'RETAIN C:\UTIL\') or
rem 2. the full _file_specification_ (e.g. 'RETAIN C:\UTIL\AUX-FILE.$$$')
rem b. the environment variable %RETAIN%
rem 1. the full _path_ only, incl. trailing '\' ('SET RETAIN=C:\UTIL\') or
rem 2. the full _file_specification_ ('SET RETAIN=C:\UTIL\AUX-FILE.$$$')
rem c. the ROOT directory of C: (C:\) (or automatically any APPENDed path) or
rem d. the ROOT directory of the CURRENT drive (\) or
rem e. the CURRENT directory (.\) or
rem f. the PARENT directory of the current one (..\) or
rem g. the SAME directory where RETAIN.BAT is residing:
rem if EXPLICITELY specified when starting RETAIN (DOS 3.x&up only).
rem (NOT if RETAIN.BAT can only be found via the PATH!) or
rem h. the DOS PATH variable (this may take quite a while)
rem If the environment variable has not been set: try other location(s)
if "%RETAIN%"=="" goto NoEnvVar
rem If $RETURN$.AUX found as file specified by %RETAIN% then restart this batch
rem file (RETAIN.BAT as %0) with _full_path_&_file_name_ as the first parameter
if exist %RETAIN% %0 %RETAIN% %2
rem If $RETURN$.AUX found in path specified by %RETAIN% then restart this batch
rem file (RETAIN.BAT as %0) with _full_path_&_file_name_ as the first parameter
if exist %RETAIN%$RETURN$.AUX %0 %RETAIN%$RETURN$.AUX %2
rem If the auxiliary file thus can not be found: try other location(s) below:
:NoEnvVar
rem Check the presence of $RETURN$.AUX in (and specify _full_path_&_file_name_
rem if found):
rem (the root of C:)
if exist C:\$RETURN$.AUX %0 C:\$RETURN$.AUX %2
rem (the root of the current drive)
if exist \$RETURN$.AUX %0 \$RETURN$.AUX %2
rem (the current directory)
if exist .\$RETURN$.AUX %0 .\$RETURN$.AUX %2
rem (the parent directory)
if exist ..\$RETURN$.AUX %0 ..\$RETURN$.AUX %2
rem (the explicitely specified directory)
if exist %0\..\$RETURN$.AUX %0 %0\..\$RETURN$.AUX %2
rem ---DOSPATH---
rem Within the subroutine :Path to be called now by subsequent 'shift'ing
rem the call name for RETAIN (%0) gets lost (as well as the in version 2.0
rem introduced 2nd parameter, the alternate return file). To solve this
rem problem a temporary batch file $RETAIN$.BAT is created initially (in
rem the current directory) that contains this information hardcoded and
rem calls RETAIN (or whatever it is renamed) with the necessary parameter:
echo echo off>$RETAIN$.BAT
rem If no write of this auxiliary file is possible then cancel finally:
if not exist $RETAIN$.BAT goto NoPath
echo %0 %%1 %2>>$RETAIN$.BAT
rem At the end (or somewhere suited) remove the temporary file $RETAIN$.BAT .
rem Depending on the (path and) name (length) for RETAIN the path environment
rem variable will be used up to a certain number of characters, maximally
rem around 100.
%0 .path %path%
:NoPath
echo *** Necessary auxilary file $RETURN$.AUX could not be found - abort!
echo.
echo Specify environment variable RETAIN to point to the path where
echo $RETURN$.AUX resides (either from the DOS prompt or in AUTOEXEC.BAT).
echo E.g. SET RETAIN=C:\UTIL\ (terminated with backslash).
echo Or specify full path and file name to the eventual alternate auxiliary
echo file for $RETURN$.AUX (e.g. SET RETAIN=C:\UTIL\AUX-FILE.$$$).
echo.
echo Or specify path (terminated with '\') to or full file specification
echo for $RETURN$.AUX as the first (and only) parameter for %0
goto end
:AltRtn
rem Determine return-file (if not specified already as the second argument)
if "%RETURN%"=="" %0 %1 C:\RETURN
%0 %1 %RETURN%
:RETAIN
if not "%3"=="" goto AuxPath_checked
rem Now %3 is empty: aux-path[aux-file] %1 specified by user, check existence:
rem If %1 is _full_path_&_file_name_ of (alternate) $RETURN$.AUX then continue
if exist %1 goto AuxPath_checked
rem If %1 is path only to explicit $RETURN$.AUX then restart RETAIN (%0) with
rem _full_path_&_file_name_ as the first parameter
if exist %1$RETURN$.AUX %0 %1$RETURN$.AUX %2
rem %1 has been specified by the user, but $RETURN$.AUX could not be found:
echo *** Auxiliary path[file] %1 is incorrect, file $RETURN$.AUX not found.
echo Now trying to find $RETURN$.AUX using path (or full file specification):
echo 1. from environment variable RETAIN (path or full file specification)
echo 2. the root directory of C: (C:\) (or automatically any APPENDed path)
echo 3. the root of the current drive (\)
echo 4. the current directory (.\)
echo 5. the parent directory (..\)
echo 6. the same directory as RETAIN.BAT if RETAIN has been called by path
echo 7. from the DOS PATH variable (this may take quite a while)
echo.
goto Determine
:AuxPath_checked
rem Check for existence of %2.BAT (return-file): if so, nesting has to take
rem place. This is done by adding the current path parameter after the already
rem present path parameters in %2.BAT, where it calls RETAIN.
if not exist %2.BAT goto Create
rem %3 (and succeeding parameters) is the retained drive and subdirectory
rem If path(s) stored are known resume with recreation of %2.BAT
if not "%3"=="" goto Create
rem If no stored paths are known (just started RETAIN) force RETURN to
rem supply the already stored path(s) (to add the current path to).
rem This returns all currently stored paths as additional parameters up to 7
%2 %0 %1 .retain
:Create
rem This is the part to RETAIN the current drive:path
rem Creation of %2.BAT (the return-file)
if not "%1"==".recreate" if not "%9"=="" goto ListFull
rem Initially explicitely delete %2.BAT in order to see if that works:
if exist %2.BAT del %2.BAT
if exist %2.BAT goto NoDelete
echo echo off>%2.BAT
if not exist %2.BAT goto NoReturn
echo rem --- %2.BAT 2.0 (c) 1992, Jim Groeneveld>>%2.BAT
echo if "%%1"=="?" %0 ?>>%2.BAT
echo if "%%1"=="/?" %0 ?>>%2.BAT
echo if "%%1"=="-?" %0 ?>>%2.BAT
echo if %%0==%2 goto AllRight>>%2.BAT
rem Build check on unmoved/unrenamed %2.BAT into itself and
rem make sure the original return-file is being run (if it exists):
rem (this makes command lines longer, which may be undesired and unnecessary)
echo if not exist %2.BAT goto NoReturn>>%2.BAT
echo %2 %%1 %%2 %%3>>%2.BAT
echo :NoReturn>>%2.BAT
echo echo *** This file %2.BAT has been moved or renamed. DON'T! Abort!>>%2.BAT
echo echo Execution of this BATch file %%0 may cause erroneous results.>>%2.BAT
echo goto end>>%2.BAT
echo :AllRight>>%2.BAT
echo if "%%1"=="" %%0 %0 .return .retain>>%2.BAT
echo if "%%1"=="*" %%0 %0 .list .retain>>%2.BAT
echo if not "%%3"==".retain" goto Retain>>%2.BAT
if "%3"=="" goto StoreNoPath
if "%3"==".empty" if not "%1"==".recreate" goto StoreNoPath
rem %0 stores the current RETAIN.BAT file name (& eventually called path),
rem which may be renamed, into RETURN.BAT
rem %2 stores the name and location of the alternate RETURN file into it the
rem first time it is being built. This information is valid to use instead of
rem %%0 (the return file call) _as l